﻿//using Helper.Helper;
//using Newtonsoft.Json;
//using System;
//using System.Collections.Generic;

//namespace Helper.DingTalk
//{
//    public static class Msg
//    {
//        public static string roboturl = "https://oapi.dingtalk.com/robot/send?access_token=0523b403dd0304cc9fdc4c22e8f7d1abe082e63857394fecdbe8104e6b42c17a";

//        /// <summary>
//        /// 向钉钉机器人推送消息
//        /// </summary>
//        /// <param name="reporter">报告人姓名</param>
//        /// <param name="line">线路</param>
//        /// <param name="station">站点</param>
//        /// <param name="point">点位</param>
//        /// <param name="content">故障描述</param>
//        /// <param name="headphone">运维负责人电话集合</param>
//        public static void PostToMarkdown(string reportid, string reporter, string line, string station, string point, string content, List<string> headphone, string url)
//        {
//            string backurl = AppConfigurtaionServices.Configuration["BackUrl:url"];
//            try
//            {
//                RobotMarkdown model = new RobotMarkdown();
//                model.msgtype = "markdown";
//                markdownmodel md = new markdownmodel();
//                string aite = "";
//                if (headphone != null && headphone.Count > 0)
//                {
//                    foreach (var item in headphone)
//                    {
//                        aite += $"@{item},";
//                    }
//                }
                
//                md.title = "运维故障报告";
//                md.text = $"#### 运维故障报告" +
//                    "\n " +
//                    $"> {aite}" +
//                    $"{reporter}报告,故障ID-{reportid},{line},{station},{point},{content}" +
//                    "\n\n " +
//                    $"> ![screenshot]({url})\n " +
//                    $"> ###### {DateTime.Now.ToShortTimeString()}发布 [运维后台]({backurl}) ";
//                model.markdown = md;

//                atmodel at = new atmodel();

//                at.atMobiles = headphone;
//                at.isAtAll = false;
//                model.at = at;

//                var str = JsonConvert.SerializeObject(model);

//                string tempurl = AppConfigurtaionServices.Configuration["DingTalk:robot"];
//                if (!string.IsNullOrWhiteSpace(tempurl))
//                {
//                    roboturl = tempurl;
//                }

//                HttpHelper.HttpPost(roboturl,
//                  str, "application/json");
//                Common.Helper.Logger.Info($"PostToMarkdown-推送机器人,信息:{str}");
//                Common.Helper.Logger.Info($"PostToMarkdown-推送机器人,图片url:{url}");
//                Common.Helper.Logger.Info($"PostToMarkdown-推送机器人,url:{roboturl}");
//            }
//            catch (Exception ex)
//            {
//                Common.Helper.Logger.Error($"PostToMarkdown-推送机器人信息异常,异常信息{ex.ToString()}");
//            }
//        }




//        /// <summary>
//        /// 向钉钉机器人推送消息
//        /// </summary>
//        /// <param name="reporter">报告人姓名</param>
//        /// <param name="line">线路</param>
//        /// <param name="station">站点</param>
//        /// <param name="point">点位</param>
//        /// <param name="content">故障描述</param>
//        /// <param name="headphone">运维负责人电话集合</param>
//        public static void PostFinishToMarkdown(FaultInfo fault, string reporter, List<string> headphone, string url, op_fault_report_handling data)
//        {
//            string backurl = AppConfigurtaionServices.Configuration["BackUrl:url"];
//            try
//            {
//                RobotMarkdown model = new RobotMarkdown();
//                model.msgtype = "markdown";
//                markdownmodel md = new markdownmodel();
//                string aite = "";
//                if (headphone != null && headphone.Count > 0)
//                {
//                    foreach (var item in headphone)
//                    {
//                        aite += $"@{item},";
//                    }
//                }


//                md.title = "运维故障报告";

//                if (data.hasattachment=="1")
//                {
//                    md.text = $"#### 故障报告ID-{fault.reportid} 处理结果" +
//                    "\n " +
//                    $"> {aite}" +
//                    $"{reporter}报告," +
//                     "\n\n " +
//                    $"> 【故障详情】：{fault.line_name},{fault.station_name},{fault.point_name},{fault.content}" +
//                    "\n\n " +
//                    $"> 【处理结果】：{fault.state_name}" +
//                    "\n\n " +
//                      $"> 【故障诊断】：{data.fault_reason}" +
//                    "\n\n " +
//                    $"> 【处理措施】：{data.fault_handling_solve_description}" +
//                     "\n\n " +
//                    $"> 【处理人】: {data.fault_handling_solvers}" +
//                      "\n\n " +
//                    $"> 【是否存在备件更换】: 是" +
//                      "\n\n " +
//                    $"> 【备件详情】: {data.attachmentdetail}" +
//                      "\n\n " +
//                    $"> ![screenshot]({url})\n " +
//                    $"> ###### {DateTime.Now.ToShortTimeString()}发布 [运维后台]({backurl}) ";
//                }
//                else
//                {
//                    md.text = $"#### 故障报告ID-{fault.reportid} 处理结果" +
//                   "\n " +
//                   $"> {aite}" +
//                   $"{reporter}报告," +
//                    "\n\n " +
//                   $"> 【故障详情】：{fault.line_name},{fault.station_name},{fault.point_name},{fault.content}" +
//                   "\n\n " +
//                   $"> 【处理结果】：{fault.state_name}" +
//                   "\n\n " +
//                     $"> 【故障诊断】：{data.fault_reason}" +
//                   "\n\n " +
//                   $"> 【处理措施】：{data.fault_handling_solve_description}" +
//                    "\n\n " +
//                   $"> 【处理人】: {data.fault_handling_solvers}" +
//                     "\n\n " +
//                   $"> 【是否存在备件更换】: 否" +
//                     "\n\n " +
//                   $"> ![screenshot]({url})\n " +
//                   $"> ###### {DateTime.Now.ToShortTimeString()}发布 [运维后台]({backurl}) ";
//                }
               
//                model.markdown = md;

//                atmodel at = new atmodel();

//                at.atMobiles = headphone;
//                at.isAtAll = false;
//                model.at = at;

//                var str = JsonConvert.SerializeObject(model);

//                string tempurl = AppConfigurtaionServices.Configuration["DingTalk:robot"];
//                if (!string.IsNullOrWhiteSpace(tempurl))
//                {
//                    roboturl = tempurl;
//                }

//                HttpHelper.HttpPost(roboturl,
//                  str, "application/json");
//                Common.Helper.Logger.Info($"PostToMarkdown-推送机器人,信息:{str}");
//                Common.Helper.Logger.Info($"PostToMarkdown-推送机器人,图片url:{url}");
//                Common.Helper.Logger.Info($"PostToMarkdown-推送机器人,url:{roboturl}");
//            }
//            catch (Exception ex)
//            {
//                Common.Helper.Logger.Error($"PostToMarkdown-推送机器人信息异常,异常信息{ex.ToString()}");
//            }
//        }

//        /// <summary>
//        /// 钉钉机器人推送 撤销
//        /// </summary>
//        /// <param name="reportid"></param>
//        /// <param name="reporter"></param>
//        /// <param name="reason"></param>
//        /// <param name="headphone"></param>
//        public static void PostCancleToMarkdown(string reportid, string reporter, string reason, List<string> headphone)
//        {
//            string backurl = AppConfigurtaionServices.Configuration["BackUrl:url"];
//            try
//            {
//                RobotMarkdown model = new RobotMarkdown();
//                model.msgtype = "markdown";
//                markdownmodel md = new markdownmodel();
//                string aite = "";
//                if (headphone != null && headphone.Count > 0)
//                {
//                    foreach (var item in headphone)
//                    {
//                        aite += $"@{item},";
//                    }
//                }

//                md.title = "运维故障报告";
//                md.text = $"#### 故障报告ID-{reportid} 撤销提示" +
//                      "\n " +
//                    $"> {aite}" +
//                    $" {reporter}撤销" +
//                    "\n\n " +
//                      $" 【撤销原因】：{reason}" +
//                    "\n\n " +
//                    $"> ###### {DateTime.Now.ToShortTimeString()}发布 [运维后台]({backurl}) ";
//                model.markdown = md;

//                atmodel at = new atmodel();

//                at.atMobiles = headphone;
//                at.isAtAll = false;
//                model.at = at;

//                var str = JsonConvert.SerializeObject(model);

//                string tempurl = AppConfigurtaionServices.Configuration["DingTalk:robot"];
//                if (!string.IsNullOrWhiteSpace(tempurl))
//                {
//                    roboturl = tempurl;
//                }

//                HttpHelper.HttpPost(roboturl,
//                  str, "application/json");
//            }
//            catch (Exception ex)
//            {
//                Common.Helper.Logger.Error($"PostToMarkdown-推送机器人信息异常,异常信息{ex.ToString()}");
//            }
//        }
//    }
//}
